<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions">

<ui:composition template="/WEB-INF/templates/template_interno_padrao.xhtml">
	
	
	<ui:define name="conteudo">
		
		<p:growl id="growl" showDetail="false"  life="6000"/>
		
		<div class="row-fluid">
			<div class="span12" >
				<fieldset>
						<h3>
							<h:outputText value="Contas a receber" /> 
						</h3>
				</fieldset>
			</div>
		</div>
		
		<h:form id="frmListagem">
				    
		    <p:dataTable id="dataTableListagem" var="contaAReceber" value="#{contaAReceberBean.contasPendentesDePagamento}">  
  
  				<p:column headerText="Codigo" >  
  					<h:outputText value="#{contaAReceber.id}" />
		            
		        </p:column>
		        
		        <p:column headerText="Estabelecimento" > 
					<h:outputText value="#{contaAReceber.contrato.localPrestacaoServico.nome}" />
		             
		        </p:column>
		          
		        <p:column headerText="Cliente" style="width:20%;">  
		        	<h:outputText value="#{contaAReceber.contrato.contratante.nome}" />
		             
		        </p:column>  
		  
		        <p:column headerText="Serviço" style="width:15%;"> 
		        	<h:outputText value="#{contaAReceber.contrato.servicoPrincipal}" /> 
		              
		        </p:column>  
		  		
		  		<p:column headerText="Ano de referencia" style="width:5%;  text-align: center">  
		  			<h:outputText value="#{contaAReceber.anoDeReferencia}" />
		              
		        </p:column>
		  		
		  		<p:column headerText="Mês de referência" style="width:5%;  text-align: right"> 
		  			<h:outputText value="#{contaAReceber.mesDeReferencia}" /> 
		              
		        </p:column>
		        
		        <p:column headerText="Data Vencimento" style="width:5%; text-align: center"> 
		        	<h:outputText value="#{contaAReceber.dataDeVencimento}">
		        		<f:convertDateTime pattern="dd/MM/yyyy"/>
		        	</h:outputText> 
		              
		        </p:column>
		        
		        <p:column headerText="Valor" style="width:10%; text-align: right">  
		            <h:outputText value="#{contaAReceber.valorAPagar}" style="text-align: right" size="21" maxlength="21">
						<f:convertNumber type="number" locale="pt_BR" minFractionDigits="2"/>
					</h:outputText>
		        </p:column>  
		  		<p:column headerText="Ação" style="width:10%;  text-align: center">  
		              <p:commandButton action="#{contaAReceberBean.doPrepararBaixaManualDeContaAReceber(contaAReceber)}"  value="Baixa manual"  oncomplete="dlgBaixaContaAReceber.show()" update=":frmBaixa" style="font-size: 12px" >
		              </p:commandButton> <br />
		              <p:commandLink action="#{contaAReceberBean.doPrepararGeracaoBoleto()}" value="Gerar boleto"  oncomplete="dlgGerarBoleto.show()" update="@form :frmPreBoleto" style="font-size: 12px" >
		              		<f:setPropertyActionListener value="#{contaAReceber}" target="#{contaAReceberBean.contaAReceberSelecionada}" />
		              </p:commandLink>
		        </p:column>
		    </p:dataTable> 
				    
			
		</h:form>
   		
   		
   		
   		<!-- Quitar conta a receber (baixa manual)	-->
	
	
		<p:dialog id="dialogBaixaContaAReceber" 
					header="Baixa manual" 
					widgetVar="dlgBaixaContaAReceber" 
					resizable="false"  
	             	width="40%"
	             	showEffect="clip" 
	             	hideEffect="fold">  
	 				
	 				<h:form id="frmBaixa" class="form-horizontal">
		 				<h:panelGroup rendered="#{contaAReceberBean.pagamentoContaAReceberSelecionada != null}">
		 					
		 					<p:messages/>
		 					
		 					<div class="row-fluid">
	           					<div class="span12">
	           						<p:panelGrid columns="2">
	           						
	       								<h:outputLabel value="Valor a pagar"/>
				 						<h:inputText value="#{contaAReceberBean.contaAReceberSelecionada.valorAPagar}" disabled="true" style="text-align: right" size="21" maxlength="21">
										</h:inputText>
	           						
										<h:outputLabel value="Valor pago"  for="vlrpago"/>
										<pe:inputNumber id="vlrpago" value="#{contaAReceberBean.pagamentoContaAReceberSelecionada.valorPago}" decimalPlaces="2" decimalSeparator="," thousandSeparator="."  required="true" requiredMessage="Entre com o valor pago" style="text-align: right" styleClass="span12">
											<p:ajax event="blur" update="vlrpago"/>
										</pe:inputNumber>
	           						
	           						
										<h:outputLabel value="Data de pagamento" for="dtpgto" />
	     							 	<p:column style="width:10%">
											<p:calendar id="dtpgto" value="#{contaAReceberBean.pagamentoContaAReceberSelecionada.dataDePagamento}" showOn="button"  pages="2"  pattern="dd/MM/yyyy" navigator="true" locale="pt_BR" styleClass="span12" />
	      								</p:column> 
	           						
	           						
	           						</p:panelGrid>
	           					
	           					</div>
	           				</div>
		 				
		 					
		 					<div class="form-actions">
						  			<p:commandButton value="Confirmar" actionListener="#{contaAReceberBean.doConfirmarBaixa}"  process="@form" update="@form :frmListagem :growl"  oncomplete="handleBaixaContaAReceberRequest(xhr, status, args)" style="font-size: 12px" icon="ui-icon-check"/>
				                	<p:commandButton value="Fechar tela" onclick="dlgBaixaContaAReceber.hide()" icon="ui-icon-circle-close" type="button" style="font-size: 12px" />
							</div>
		 				</h:panelGroup>
	 				</h:form>
	 				
	   	</p:dialog>
	   	
	   	
	   	<!-- Gerar boleto	-->
	
	
		<p:dialog id="dialogGerarBoleto" 
					header="Gerar Boleto" 
					widgetVar="dlgGerarBoleto" 
					resizable="false"  
	             	width="50%"
	             	showEffect="clip" 
	             	hideEffect="fold">  
	 				
	 				<h:form id="frmPreBoleto" class="form-horizontal">
					
						<h:panelGroup rendered="#{contaAReceberBean.preBoleto != null}">
						
								<p>
					  			<h:outputText value="Código conta a receber: #{contaAReceberBean.contaAReceberSelecionada.id}" style="font-size: 12px"/>
					  			</p>
						
						
							  <div class="control-group">
							    <label class="control-label">Data de vencimento boleto</label>
							    <div class="controls">
							      <p:calendar id="dtVencBeleto"  value="#{contaAReceberBean.preBoleto.dataDoVencimento}" pages="2"  
										    pattern="dd/MM/yyyy" navigator="true" locale="pt_BR" showButtonPanel="false" showOn="button" 
										    required="true" requiredMessage="Entre com a data de vencimento."  >
						 				<p:ajax event="dateSelect" process="@this" update="@form" />
						 				<f:convertDateTime pattern="dd/MM/yyyy"/>
						 				<f:validator validatorId="DataVencimentoBoletoValidator"/>
						 			</p:calendar>
			 						<p:message for="dtVencBeleto"/>
							    </div>
							  </div>
						
							 <div class="control-group">
							    <label class="control-label">Valor do boleto</label>
							    <div class="controls">
										<h:inputText id="vlrDoc" label=""
											value="#{contaAReceberBean.preBoleto.valorDoDocumento}"
											validatorMessage="Entre com o valor do documento"
											onkeypress="return validaInteiroEventoKeyPress(event)"
											onkeyup="formataOnKeyUp(event, this, MASCARA_REAL, 'D')"
											styleClass="input-medium" style=" text-align: right"
											maxlength="12">
											<p:ajax event="change" listener="#{contaAReceberBean.preBoleto.doValorDocumentoBoletoAlterado}" process="@this" update="@form" />
											<f:validateDoubleRange minimum="0.1" />
											<f:convertNumber type="number" locale="pt_BR" minFractionDigits="2" maxFractionDigits="2" />
										</h:inputText>
										<p:message for="vlrDoc" />
									</div>
							  </div>
							<div class="control-group">
						    	<label class="control-label">Perc. juros de mora</label>
						    	<div class="controls">
						    		<div class="input-append">
										<h:inputText id="percJurosMoral" label=""
											value="#{contaAReceberBean.preBoleto.percentualJurosMora}"
											onkeypress="return validaInteiroEventoKeyPress(event)"
											onkeyup="formataOnKeyUp(event, this, MASCARA_REAL, 'D')"
											styleClass="input-mini" style="text-align: right" maxlength="6">
											<f:convertNumber type="number" locale="pt_BR" minFractionDigits="2" maxFractionDigits="3" />
											<p:ajax event="change" listener="#{contaAReceberBean.preBoleto.doPercentualJurosMoraBoletoAlterado}" process="@this" update="@form" />
										</h:inputText>
										<span class="add-on">%</span>
									</div>
									&nbsp;
									<div class="input-prepend">
										<span class="add-on">R$</span>
										<h:inputText id="vlrJurosMoral" label=""
											value="#{contaAReceberBean.preBoleto.valorJurosMora}"
											onkeypress="return validaInteiroEventoKeyPress(event)"
											onkeyup="formataOnKeyUp(event, this, MASCARA_REAL, 'D')"
											styleClass="input-small" style="text-align: right"
											disabled="true" maxlength="6">
											<f:convertNumber type="number" locale="pt_BR" minFractionDigits="2" maxFractionDigits="2" />
										</h:inputText>
									</div>
								</div>
						  	</div>	
							
							<div class="control-group">
						    	<label class="control-label">Perc. multa após venc.</label>
						    	<div class="controls">
						    		<div class="input-append">
										<h:inputText id="percMulta" label=""
											value="#{contaAReceberBean.preBoleto.percentualMulta}"
											onkeypress="return validaInteiroEventoKeyPress(event)"
											onkeyup="formataOnKeyUp(event, this, MASCARA_REAL, 'D')"
											styleClass="input-mini" style="text-align: right" maxlength="6">
											<p:ajax event="change" listener="#{contaAReceberBean.preBoleto.doPercentualMultaAposVencimentoBoletoAlterado}" process="@this" update="@form" />
											<f:convertNumber type="number" locale="pt_BR" minFractionDigits="2" maxFractionDigits="2" />
										</h:inputText>
										<span class="add-on">%</span>
									</div>
									&nbsp;
									<div class="input-prepend">
										<span class="add-on">R$</span>
										<h:inputText id="vlrMulta" label=""
											value="#{contaAReceberBean.preBoleto.valorMulta}"
											onkeypress="return validaInteiroEventoKeyPress(event)"
											onkeyup="formataOnKeyUp(event, this, MASCARA_REAL, 'D')"
											styleClass="input-small" style="text-align: right"
											disabled="true" maxlength="6">
											<f:convertNumber type="number" locale="pt_BR"
												minFractionDigits="2" maxFractionDigits="2" />
										</h:inputText>
									</div>
								</div>
						  	</div>
							<div class="control-group">
							    <label class="control-label">Não receber após</label>
							    <div class="controls">
							      <div class="input-append">
									<h:inputText id="naoRecebAposXDias" label=""
											value="#{contaAReceberBean.preBoleto.carteiraBoleto.naoReceberAposXDias}"
											onkeypress="return validaInteiroEventoKeyPress(event)"
											styleClass="input-mini" style="text-align: right" maxlength="4">
										<f:convertNumber type="number" locale="pt_BR" minFractionDigits="0" />
										<p:ajax event="change" process="@this" update="@form" />
									</h:inputText>
									<span class="add-on">dias</span>
								</div>
							    </div>
							  </div>
							  
							
							<div class="form-actions">
								
				            	<p:commandButton id="downloadLink" value="Gera Boleto" ajax="false"  onclick="PrimeFaces.monitorDownload(start_download, stop_download)"  icon="ui-icon-arrowthichk-s" styleClass="btn btn-primary" >  
		  							<p:fileDownload value="#{contaAReceberBean.preBoleto.file}" />  
								</p:commandButton>  
								&nbsp;
								<p:commandButton value="Fechar tela" onclick="dlgGerarBoleto.hide()" icon="ui-icon-circle-close" type="button" />
							</div>
						</h:panelGroup>
					
					


				</h:form>
	 				
	   	</p:dialog>
	   	
	   	<p:dialog modal="true" widgetVar="statusDialog" header="Status" draggable="false" closable="false" resizable="false">  
    		<p:graphicImage value="/resources/img/ajaxloadingbar.gif" />  
		</p:dialog> 
	   	
	   	<script type="text/javascript">  
		    function handleBaixaContaAReceberRequest(xhr, status, args) {  
		        if(!args.isOk) {  
		            jQuery('#dialogBaixaContaAReceber').effect("shake", { times:3 }, 100);  
		        } else {  
		            jQuery('#dialogBaixaContaAReceber').fadeOut();
		        }  
		    }

		    function start_download() {  
		        PF('statusDialog').show();  
		    }  
		      
		    function stop_download() { 
		    	PF('statusDialog').hide(); 
		        PF('dlgGerarBoleto').hide();  
		    }  
		</script> 
		
	</ui:define>

</ui:composition>      
	
</html>